#pragma once 
#include "eventloopthreadpool.h"
#include "channel/serversocketchannel.h"
#include "channel/socketchannel.h"
namespace TinyRPC{
class TcpServer{
public:
    TcpServer(EventLoop* baseLoopPtr, int threadNum);
    virtual void start();
    ~TcpServer();
    
protected:
// 
    EventLoop* getNextLoop(){
        if(m_eventLoopPool.empty()){
            return m_baseLoopPtr;
        }else{
            return m_eventLoopPool.getNextLoop((m_nextLoopIndex++) % m_threadNum);
        }
    }

    void co_echo(SocketChannelPtr socketChannel);
    void co_accept(INetAddress address);
    
protected:
    int m_threadNum;
    
    EventLoop* m_baseLoopPtr;
    EventLoopThreadPool m_eventLoopPool;
    uint32_t m_nextLoopIndex;
};
}
